package com.Service;

import com.Dao.AddressDao;
import com.POJO.Address;
import com.Service.Imp.AddressServiceImp;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Service
public class AddressService extends ServiceImpl<AddressDao, Address> implements AddressServiceImp {
    @Autowired
    private AddressDao addressDao;

    public List<Address> findAddress(String tel){
        QueryWrapper<Address> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("tel",tel);
        return addressDao.selectList(queryWrapper);
    }
    public int addAddress(Map<String,String> Map_All){
        Address address=new Address();
        String tel=Map_All.get("tel");
        address.setTel(tel);
        String username=Map_All.get("username");
        address.setUsername(username);
        String province=Map_All.get("province");
        address.setProvince(province);
        String city=Map_All.get("city");
        address.setCity(city);
        String area=Map_All.get("area");
        address.setArea(area);
        String addressIp=Map_All.get("addressIp");
        address.setAddressIp(addressIp);
        BigDecimal longitude=new BigDecimal(Map_All.get("longitude"));
        address.setLongitude(longitude);
        BigDecimal latitude=new BigDecimal(Map_All.get("latitude"));
        address.setLatitude(latitude);
        return addressDao.insert(address);
    }
    public int delAddress(int id){
        return addressDao.deleteById(id);
    }

}
